﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region CementReview

        public List<tb_RPT_CementReview> GetAllCementReview()
        {

            var query = (from obj in this.tb_RPT_CementReviews
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }
        public List<tb_RPT_CementReview> GetCementReviewByProjectName(string strProjectName)
        {

            var query = (from obj in this.tb_RPT_CementReviews
                         where obj.IsDelete == 0 && obj.ProjectName == strProjectName
                         select obj).ToList();
            return query;
        }

        public List<tb_RPT_CementReview> GetCementReviewByContition(string strProjectName, string strProdCode,
                                                                            string strFactoryNumbers, string strIntoFactoryDate,
                                                                            string strTestDate)
        {
            var tq = from obj in this.tb_RPT_CementReviews
                     where obj.IsDelete == 0
                     select obj;

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }
            if (strProdCode.Length > 0)
            {
                tq = tq.Where(entity => entity.ProdCode == strProdCode);
            }
            if (strFactoryNumbers.Length > 0)
            {
                tq = tq.Where(entity => entity.FactoryNumbers == strFactoryNumbers);
            }
            if (strIntoFactoryDate.Length > 0)
            {
                tq = tq.Where(entity => entity.IntoFactoryDate == strIntoFactoryDate);
            }
            if (strTestDate.Length > 0)
            {
                tq = tq.Where(entity => entity.TestDate == strTestDate);
            }
            

            var query = tq.ToList();
            return query;
        }

        public tb_RPT_CementReview GetCementReviewById(int id)
        {
            return this.tb_RPT_CementReviews.SingleOrDefault(tb_RPT_CementReviews => tb_RPT_CementReviews.Id == id);
        }

        public void CreateCementReview(tb_RPT_CementReview entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_CementReviews.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyCementReview(tb_RPT_CementReview entity)
        {
            tb_RPT_CementReview instance = this.tb_RPT_CementReviews.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.ProjectName = entity.ProjectName;
            instance.ProdCode = entity.ProdCode;
            instance.FactoryNumbers = entity.FactoryNumbers;
            instance.IntoFactoryDate = entity.IntoFactoryDate;
            instance.TestDate = entity.TestDate;
            instance.STANStandardConsistency = entity.STANStandardConsistency;
            instance.STANSpecSurfaceArea = entity.STANSpecSurfaceArea;
            instance.STANScreenResidue = entity.STANScreenResidue;
            instance.STANCakeMethod = entity.STANCakeMethod;
            instance.STANLeiMethod = entity.STANLeiMethod;
            instance.STANInitialSet = entity.STANInitialSet;
            instance.STANFinalSet = entity.STANFinalSet;
            instance.STANAveBendingStrength3D = entity.STANAveBendingStrength3D;
            instance.STANAveBendingStrength28D = entity.STANAveBendingStrength28D;
            instance.STANAveCompressiveStrength3D = entity.STANAveCompressiveStrength3D;
            instance.STANAveCompressiveStrength28D = entity.STANAveCompressiveStrength28D;
            instance.MEASUStandardConsistency = entity.MEASUStandardConsistency;
            instance.MEASUSpecSurfaceArea = entity.MEASUSpecSurfaceArea;
            instance.MEASUScreenResidue = entity.MEASUScreenResidue;
            instance.MEASUCakeMethod = entity.MEASUCakeMethod;
            instance.MEASULeiMethod = entity.MEASULeiMethod;
            instance.MEASUInitialSet = entity.MEASUInitialSet;
            instance.MEASUFinalSet = entity.MEASUFinalSet;
            instance.MEASUAveBendingStrength3D = entity.MEASUAveBendingStrength3D;
            instance.MEASUAveBendingStrength28D = entity.MEASUAveBendingStrength28D;
            instance.MEASUAveCompressiveStrength3D = entity.MEASUAveCompressiveStrength3D;
            instance.MEASUAveCompressiveStrength28D = entity.MEASUAveCompressiveStrength28D;
            instance.TestStandard = entity.TestStandard;
            instance.TestResult = entity.TestResult;
            instance.Remark = entity.Remark;
            instance.Review = entity.Review;
            instance.Approval = entity.Approval;
            instance.Test = entity.Test; 
            

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteCementReview(tb_RPT_CementReview entity)
        {
            tb_RPT_CementReview deleteEntity = tb_RPT_CementReviews.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_CementReviews.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
